*****************************************************************
*********** Mining and violent competition in Africa ************
****** A.S. Rigterink, T. Ghani, J.S. Lozano, J.N. Shapiro ******
****** Replication of Tables in section C of the Appendix *******

/*
0. Setting globals
1. Tables C1 and C3
2. Table C2
3. Tables C4 and C5
4. Tables C6 and C7
5. Tables C8 and C9
6. Table C10, and Figures C1 and C2
7. Tables C11 and C12
8. Table C13, and Figures C3 and C4
9. Table C14
10. Table C15, and Figures C5 and C6
*/
******************************************************************

clear all
version 17.0
set more off
cap log close

/*--------------------------------
------- 0. Setting globals -------
----------------------------------*/

*** Directory globals
*** NB: SET YOUR DIRECTORY HERE AND UNTEXT IF NOT RUNNING 0-Master.do
*global dir = ".\Replication_data\Stata"
*cd "$dir"

*** Subdirectories
global Do_files     "./Do"
global Data			"./Data"
global Results		"./Results"
global Tables 		"./Tables"
global Figures		"./Figures"

*** Scripts for spatially clustered standard errors
do "$Do_files/my_ols_spatial_HAC.do"
do "$Do_files/my_reg2hdfespatial.ado"

** Variable globals
global eventtypes "battle civ civ_gov civ_reb protest_peace riot"
global snl_owner_types_known "owner_isin"
global snl_op_types_known "op_isin"
global snl_owner_types_c_kn "owner_tax owner_local owner_chn owner_oecd9"
global snl_op_types_c_kn "op_local op_chn op_oecd9"
global snl_owner_size "owner_size owner_large" 
global snl_op_size "op_size op_large"

*** Load data
use "$Data/main.dta"

/*------------------------------------------
------------ 1. Tables C1 and C3 -----------
--------------------------------------------*/

*** Variables based on operator name 
foreach X in $snl_op_types_known {
    my_reg2hdfespatial acled_indicator snl_price op_known_price `X'_price asm_price snl_asm_price op_known_asm_price `X'_asm_price, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
	estimates save "$Results/Table_het_`X'", replace
	
	my_reg2hdfespatial acled_indicator snl_price op_known_price `X'_price asm_price snl_asm_asmprice op_known_asm_price_a `X'_asm_price_a, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
	estimates save "$Results/Table_het_`X'_a", replace
	
}

*** Variables based on operator country of registration
foreach X in $snl_op_types_c_kn {
    my_reg2hdfespatial acled_indicator snl_price op_c_kn_price `X'_price asm_price snl_asm_price op_c_kn_asm_price `X'_asm_price, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
	estimates save "$Results/Table_het_`X'", replace
	
	my_reg2hdfespatial acled_indicator snl_price op_c_kn_price `X'_price asm_price snl_asm_asmprice op_c_kn_asm_price_a `X'_asm_price_a, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
	estimates save "$Results/Table_het_`X'_a", replace
	
}

/*----------------------------------
------------ 2. Table C2 -----------
------------------------------------*/

*** Variables based on owner name
foreach X in $snl_owner_types_known {
	my_reg2hdfespatial acled_indicator snl_price owner_known_price `X'_price asm_price snl_asm_asmprice owner_known_asm_price_a `X'_asm_price_a, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
	estimates save "$Results/Table_het_`X'_a", replace
	
}

*** Variables based on owner country of registration
foreach X in $snl_owner_types_c_kn {
	my_reg2hdfespatial acled_indicator snl_price owner_c_kn_price `X'_price asm_price snl_asm_asmprice owner_c_kn_asm_price_a `X'_asm_price_a, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
	estimates save "$Results/Table_het_`X'_a", replace
	
}

/*----------------------------------
----------- 3. Tables C4 and C5 ----
------------------------------------*/

*** Owners 
foreach X in $snl_owner_size {
    my_reg2hdfespatial acled_indicator snl_price owner_known_price `X'_price asm_price snl_asm_price owner_known_asm_price `X'_asm_price, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
	estimates save "$Results/Table_het_`X'", replace
	
	my_reg2hdfespatial acled_indicator snl_price owner_known_price `X'_price asm_price snl_asm_asmprice owner_known_asm_price_a `X'_asm_price_a, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
	estimates save "$Results/Table_het_`X'_a", replace
	
}

*** Operators 
foreach X in $snl_op_size {
    my_reg2hdfespatial acled_indicator snl_price op_known_price `X'_price asm_price snl_asm_price op_known_asm_price `X'_asm_price, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
	estimates save "$Results/Table_het_`X'", replace
	
	my_reg2hdfespatial acled_indicator snl_price op_known_price `X'_price asm_price snl_asm_asmprice op_known_asm_price_a `X'_asm_price_a, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
	estimates save "$Results/Table_het_`X'_a", replace
	
}

/*----------------------------------
----------- 4. Tables C6 and C7 ----
------------------------------------*/

*** Variables based on owner/operator name
* Owner
foreach X in owner_isin {
    my_reg2hdfespatial acled_indicator snl_price owner_known_price owner_size_price `X'_price  asm_price snl_asm_price owner_known_asm_price owner_size_asm_price `X'_asm_price, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
	estimates save "$Results/Table_het_`X'_s", replace
}

* Operator 
foreach X in op_isin {
    my_reg2hdfespatial acled_indicator snl_price op_known_price op_size_price `X'_price asm_price snl_asm_price op_known_asm_price op_size_asm_price `X'_asm_price, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
	estimates save "$Results/Table_het_`X'_s", replace
	
}

** Variables based on owner/operator location
* Owner 
foreach X in $snl_owner_types_c_kn {
    my_reg2hdfespatial acled_indicator snl_price owner_known_price owner_size_price owner_c_kn_price `X'_price asm_price snl_asm_price owner_c_kn_asm_price owner_known_asm_price owner_size_asm_price `X'_asm_price, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
	estimates save "$Results/Table_het_`X'_s", replace
}

* Operator 
foreach X in $snl_op_types_c_kn {
    my_reg2hdfespatial acled_indicator snl_price op_known_price op_size_price op_c_kn_price `X'_price asm_price snl_asm_price op_known_asm_price op_size_asm_price op_c_kn_asm_price `X'_asm_price, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
	estimates save "$Results/Table_het_`X'_s", replace
	
}

/*----------------------------------
----------- 5. Tables C8 and C9 ----
------------------------------------*/

foreach X in owner_known op_known owner_c_kn op_c_kn {
	my_reg2hdfespatial acled_indicator snl_price `X'_price asm_price snl_asm_price `X'_asm_price, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
	estimates save "$Results/Table_het_`X'", replace
	
	my_reg2hdfespatial acled_indicator snl_price `X'_price asm_price snl_asm_asmprice `X'_asm_price_a, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
	estimates save "$Results/Table_het_`X'_a", replace
}

/*--------------------------------------------------
----------- 6. Table C10, and Figures C1 and C2 ----
----------------------------------------------------*/

foreach X in lsm asm {
	
	my_reg2hdfespatial acled_indicator snl_price asmgold_`X'price asmdiamond_`X'price asm2c_`X'price asm3t_`X'price snl_asmgold_`X'price snl_asmdiamond_`X'price snl_asm2c_`X'price snl_asm3t_`X'price, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
	
	estimates save "$Results/Table_het_comm_`X'price", replace
}

/*------------------------------------------
---------- 7. Tables C11 and C12 -----------
--------------------------------------------*/

foreach X in $eventtypes {
	my_reg2hdfespatial `X'_indicator snl_price asm_price snl_asm_price, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
	estimates save "$Results/Table_het_`X'", replace
	
	my_reg2hdfespatial `X'_indicator snl_price asm_price snl_asm_asmprice, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
	estimates save "$Results/Table_het_`X'_a", replace
}

/*--------------------------------------------------
----------- 8. Table C13, and Figures C3 and C4 ----
----------------------------------------------------*/

my_reg2hdfespatial acled_indicator snl_price_chneg snl_price_chpos asm_price_chneg asm_price_chpos snl_asm_price_chpos snl_asm_price_chneg, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
estimates save "$Results/Table_het_posneg_bin", replace

my_reg2hdfespatial acled_indicator snl_price_chneg snl_price_chpos asm_price_chneg asm_price_chpos snl_asm_asmprice_chneg snl_asm_asmprice_chpos, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
estimates save "$Results/Table_het_posneg_bin_a", replace

drop snl_price_chneg snl_price_chpos snl_asm_price_chneg snl_asm_price_chpos asm_price_chneg asm_price_chpos snl_asm_asmprice_chneg snl_asm_asmprice_chpos 

my_reg2hdfespatial acled_indicator snl_price_ch* asm_price_ch* snl_asm_price_ch*, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
estimates save "$Results/Table_het_posneg_cat", replace

my_reg2hdfespatial acled_indicator snl_price_ch* asm_price_ch* snl_asm_asmprice_ch*, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
estimates save "$Results/Table_het_posneg_cat_a", replace

/*-----------------------------------
------------ 9. Table C14 -----------
-------------------------------------*/

my_reg2hdfespatial acled_indicator snl_price snlmulti_price asm_price snl_asm_price snlmulti_asm_price, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
estimates save "$Results/Table_het_multi", replace

my_reg2hdfespatial acled_indicator snl_price snlmulti_price asm_price snl_asm_asmprice snlmulti_asm_asmprice, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
estimates save "$Results/Table_het_multi_a", replace

/*--------------------------------------------------
---------- 10. Table C15, and Figures C5 and C6 ----
----------------------------------------------------*/

my_reg2hdfespatial acled_indicator snl_price asm_price snl_asm_price near_snl_price near_asm_price near_snl_asm_price, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
estimates save "$Results/Table_het_splag", replace

my_reg2hdfespatial acled_indicator snl_price asm_price snl_asm_asmprice near_snl_price near_asm_price near_snl_asm_asmprice, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
estimates save "$Results/Table_het_splag_a", replace

my_reg2hdfespatial acled_indicator snl_price asm_price snl_asm_price near_snl_price near_asm_price near_snl_asm_price nearsnl_snl nearsnl_asm nearsnl_snl_asm nearasm_snl nearasm_asm nearasm_snl_asm nearboth_snl nearboth_asm nearboth_snl_asm, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
estimates save "$Results/Table_het_splag_full", replace

my_reg2hdfespatial acled_indicator snl_price asm_price snl_asm_asmprice near_snl_price near_asm_price near_snl_asm_asmprice nearsnl_snl nearsnl_asm nearsnl_snl_asm_asmprice nearasm_snl nearasm_asm nearasm_snl_asm_asmprice nearboth_snl nearboth_asm nearboth_snl_asm_asmprice, timevar(it) panelvar(cell) lat(y) lon(x) distcutoff(500) lagcutoff(100000) 
estimates save "$Results/Table_het_splag_full_a", replace


